package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.PubReceiptBean;
import com.koron.css2.baseConfig.mapper.PubReceiptMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.CommonUtils;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import com.koron.util.ValidationKey;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bson.types.ObjectId;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 * 单据类型添加
 * @author 
 *
 */
public class ReceiptAdd implements ServerInterface {

	private static Logger logger = LogManager.getLogger(ReceiptAdd.class);
	@Override
	@ValidationKey(clazz = PubReceiptBean.class,method = "insert")
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		PubReceiptMapper mapper = factory.getMapper(PubReceiptMapper.class);
		PubReceiptBean bean = null;
		try {
			bean = JsonUtils.objectToPojo(req.getData(), PubReceiptBean.class);
			bean.setCreateName(userInfo.getUserInfo().getName());
			bean.setCreateTime(CommonUtils.getCurrentTime());
			bean.setReceiptId(new ObjectId().toHexString());
			mapper.saveReceipt(bean);
		} catch (Exception e) {
			logger.error("非法参数",e);
			return MessageBean.create(Constant.ILLEGAL_PARAMETER, "非法参数", void.class);
		}
		return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
		}

}
